{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4d151906-66f2-48e2-9567-727d2da6a3be",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pydantic import BaseModel, Field\n",
    "import typing\n",
    "from typing import TypeVar, Generic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "70db73fb-40a1-47bf-8314-c29f24604b84",
   "metadata": {},
   "outputs": [],
   "source": [
    "class responseModel(BaseModel, Generic[T]):\n",
    "    returnCode: typing.Annotated[str, Field(description='响应状态码')]='0'\n",
    "    returnMessage: typing.Annotated[str, Field(description='响应状态信息，通常为\"成功\"或错误信息')] = \"Query Succeed\"  # 添加默认值\n",
    "    rowCount: typing.Annotated[int, Field(description='响应数据行数，通常为查询结果的数量')] = 0\n",
    "    colCount: typing.Annotated[int, Field(description='响应数据列数，通常为查询结果的字段数量')] = 0\n",
    "    requestParams: typing.Annotated[str, Field(description='请求参数，通常为查询条件或其他相关参数')] = ''\n",
    "    requestTime: typing.Annotated[str, Field(description='请求时间，通常为ISO格式的时间字符串')] = ''\n",
    "    responseTime: typing.Annotated[str, Field(description='响应时间，通常为ISO格式的时间字符串')] = ''\n",
    "    takeTime: typing.Annotated[float, Field(description='请求处理时间，单位为秒')] = 0.0\n",
    "    fieldNames: typing.Annotated[str, Field(description='响应数据的字段名称列表')] = 'null'\n",
    "    fieldUnits: typing.Annotated[str, Field(description='响应数据的字段单位列表')] = 'null'\n",
    "    DS:typing.Annotated[T, Field(description='响应内容，类型由泛型参数 T 决定')]='null'\n",
    "\n",
    "    class Config:\n",
    "        extra = \"allow\"  # 允许额外字段"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "31af9cec-05db-4c12-a057-3d7b9deb3ae8",
   "metadata": {},
   "outputs": [],
   "source": [
    "repm=responseModel(\n",
    "    returnCode='0',\n",
    "    returnMessage='Query Succeed',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "8ee93cf1-cc52-4c15-975a-baaae820416c",
   "metadata": {},
   "outputs": [],
   "source": [
    "repm.test='fsdfsf'\n",
    "repm.teeeee=None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "4a6b4329-96f7-4cc0-ad60-c7fe39c7738c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"returnCode\":\"0\",\"returnMessage\":\"Query Succeed\",\"rowCount\":0,\"colCount\":0,\"requestParams\":\"\",\"requestTime\":\"\",\"responseTime\":\"\",\"takeTime\":0.0,\"fieldNames\":\"null\",\"fieldUnits\":\"null\",\"DS\":\"null\",\"test\":\"fsdfsf\",\"teeeee\":null}'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "repm.model_dump_json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f60049fd-6d34-4af4-9889-06900b6f63e4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1590429-55a8-4667-beac-cc88730ae1ca",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2aff09b-9a46-466e-859e-c60b76117193",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57121f7d-8f78-42dd-8985-d899742db71e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23a2d0fa-e84a-4664-9f71-dea01b47f7c9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d6902ae-521d-4a68-bd2e-1f7df7bf0521",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aefdbb4f-ecdb-424c-9cff-2000c4f445a1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf8eeb7f-39ac-43f6-970a-3b654d55bf75",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:webdev]",
   "language": "python",
   "name": "conda-env-webdev-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
